const axios = require('axios');
const template = require('../../utils/template');
const cheerio = require('cheerio');
const config = require('../../config');

const baseUrl = 'https://language.chinadaily.com.cn/news_bilingual'
module.exports = async (ctx) => {
    const response = await axios({
        method: 'get',
        url: baseUrl,
        headers: {
            'User-Agent': config.ua,
            // 'Host': 'toutiao.io'
        },
        responseType: 'text'
    });
    const $ = cheerio.load(response.data);
    const title = '双语';

    const list = $('.content_left>.gy_box', '.content');
    const article_item = [];
    for (let i = 0; i < list.length; i++) {
        const article_el = $(list[i]).find('.gy_box_txt>.gy_box_txt2').eq(0);
        const item = {
            title: article_el.find('a').eq(0).text(),
            link: 'https://' + article_el.find('a').eq(0).attr('href')
        };
        article_item.push(item);
    }
    ;
    ctx.body = template({
        title: '英语点津-' + title,
        link: baseUrl,
        item: article_item,
    });
};
